package com.cms.web.queryAnalyse;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PathVariable;

import com.mrp.persistence.queryAnalyse.pageQuery.bean.EMPPageQuery;
import com.persistence.qxgl.beans.SYSUser;
import com.web.BaseController;

import com.cms.biz.business.CMSGeneralContractServiceMgr;
import com.cms.biz.queryAnalyse.CMSQueryAnalyseServiceMgr;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.eai.data.JParamObject;
import com.efounder.eai.data.JResponseObject;
import com.enums.EMPQueryParamEnum;

@Controller
@RequestMapping(value="/cmsContractQueryAnalyse")
public class EMPContractQueryAnalyseController extends BaseController{
	@Autowired
	private             CMSGeneralContractServiceMgr                           generalContractMgr;

	@Autowired
	private                CMSQueryAnalyseServiceMgr                       queryAnalyseServiceMgr;
	
	@Autowired
	public HttpSession session;

	@RequestMapping("/XSContractList")
	public String XSContractList(@RequestParam String F_DJLX, @RequestParam String F_HTMC, EMPPageQuery page, Model model) {
		JParamObject           PO = JParamObject.Create();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		String         BILL_WHERE = " F_DJLX like '" + F_DJLX + "%' and F_HTMC like '" + F_HTMC + "%' ";
		
		if(F_DJLX.equals("WXHT")) {
			BILL_WHERE += " and F_BMBH = '" + user.getUSER_ORGID() + "'";
		}
		PO.SetValueByParamName("TABLE_NAME", "HTXXZD");
		PO.SetValueByParamName("F_DJLX", F_DJLX);
		PO.SetValueByParamName("sqlWhere", BILL_WHERE);
		PO.SetValueByParamName("sqlOrderBy", " HTXXZD.F_HTBH desc");
		EFDataSet queryDataSet = generalContractMgr.loadCMSGeneralContract(PO);
		model.addAttribute("queryDataSet", queryDataSet);
		model.addAttribute("page", page);
		model.addAttribute("F_DJLX", F_DJLX);
		model.addAttribute("F_HTMC", F_HTMC);
		return "/cms/queryAnalyse/XSHT/xshtList";
	}
	
	@RequestMapping("/WXContractList")
	public String WXContractList(@RequestParam String F_DJLX, @RequestParam String F_HTMC, EMPPageQuery page, Model model) {
		JParamObject           PO = JParamObject.Create();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		String         BILL_WHERE = " F_DJLX like '" + F_DJLX + "%' and F_HTMC like '" + F_HTMC + "%' ";
		
		if(F_DJLX.equals("WXHT")) {
			BILL_WHERE += " and F_BMBH = '" + user.getUSER_ORGID() + "'";
		}
		PO.SetValueByParamName("TABLE_NAME", "HTXXZD");
		PO.SetValueByParamName("F_DJLX", F_DJLX);
		PO.SetValueByParamName("sqlWhere", BILL_WHERE);
		PO.SetValueByParamName("sqlOrderBy", " HTXXZD.F_HTBH desc");
		EFDataSet queryDataSet = generalContractMgr.loadCMSGeneralContract(PO);
		model.addAttribute("queryDataSet", queryDataSet);
		model.addAttribute("page", page);
		model.addAttribute("F_DJLX", F_DJLX);
		model.addAttribute("F_HTMC", F_HTMC);
		return "/cms/queryAnalyse/WXHT/xshtList";
	}
	
	/**
	 * 未付款合同查询
	 * @param F_CKBH
	 * @param model
	 * @return
	 */
	@RequestMapping("/XSUnpaidContractInfoQuery")
	public String XSUnpaidContractInfoQuery(@RequestParam String F_DJLX, @RequestParam String F_HTMC, EMPPageQuery page, Model model) {
		JParamObject           po = JParamObject.Create();
		EFDataSet    queryDataSet = null;
		EFRowSet      queryRowSet = null;

		po.SetValueByParamName("F_HTMC", F_HTMC);
		po.SetValueByParamName("F_DJLX", F_DJLX);
		po.setValue(EMPQueryParamEnum.PAGEQUERY, page);
		
		JResponseObject        RO = queryAnalyseServiceMgr.searchUnpaidContractInfo(po);
		queryRowSet = (EFRowSet) RO.getResponseObject();
		
		queryDataSet = queryRowSet.getDataSet(EMPQueryParamEnum.QUERYRESULT);
		page = (EMPPageQuery) queryRowSet.getExtProperty(EMPQueryParamEnum.PAGEQUERY, null);
		model.addAttribute("queryDataSet", queryDataSet);
		model.addAttribute("page", page);
		model.addAttribute("F_HTMC", F_HTMC);
		model.addAttribute("F_DJLX", F_DJLX);
		return "/cms/queryAnalyse/XSHT/unpaidContractInfoList";
	}
	
	/**
	 * 未付款合同查询
	 * @param F_CKBH
	 * @param model
	 * @return
	 */
	@RequestMapping("/WXUnpaidContractInfoQuery")
	public String WXUnpaidContractInfoQuery(@RequestParam String F_DJLX, @RequestParam String F_HTMC, EMPPageQuery page, Model model) {
		JParamObject           po = JParamObject.Create();
		EFDataSet    queryDataSet = null;
		EFRowSet      queryRowSet = null;

		po.SetValueByParamName("F_HTMC", F_HTMC);
		po.SetValueByParamName("F_DJLX", F_DJLX);
		po.setValue(EMPQueryParamEnum.PAGEQUERY, page);
		
		JResponseObject        RO = queryAnalyseServiceMgr.searchUnpaidContractInfo(po);
		queryRowSet = (EFRowSet) RO.getResponseObject();
		
		queryDataSet = queryRowSet.getDataSet(EMPQueryParamEnum.QUERYRESULT);
		page = (EMPPageQuery) queryRowSet.getExtProperty(EMPQueryParamEnum.PAGEQUERY, null);
		model.addAttribute("queryDataSet", queryDataSet);
		model.addAttribute("page", page);
		model.addAttribute("F_HTMC", F_HTMC);
		model.addAttribute("F_DJLX", F_DJLX);
		return "/cms/queryAnalyse/WXHT/unpaidContractInfoList";
	}
	
	/**
	 * 已付款合同查询
	 * @param F_CKBH
	 * @param model
	 * @return
	 */
	@RequestMapping("/paidContractInfoQuery/{F_GUID}")
	public String paidContractInfoQuery(@PathVariable("F_GUID") String F_GUID, EMPPageQuery page, Model model) {
		JParamObject           po = JParamObject.Create();
		EFDataSet    queryDataSet = null;
		EFRowSet      queryRowSet = null;

		po.SetValueByParamName("F_GUID", F_GUID);

		po.setValue(EMPQueryParamEnum.PAGEQUERY, page);
		
		JResponseObject        RO = queryAnalyseServiceMgr.searchPaidContractInfo(po);
		queryRowSet = (EFRowSet) RO.getResponseObject();
		
		queryDataSet = queryRowSet.getDataSet(EMPQueryParamEnum.QUERYRESULT);
		page = (EMPPageQuery) queryRowSet.getExtProperty(EMPQueryParamEnum.PAGEQUERY, null);
		model.addAttribute("queryDataSet", queryDataSet);
		model.addAttribute("page", page);
		model.addAttribute("F_GUID", F_GUID);
		return "/cms/queryAnalyse/paidContractInfoList";
	}
}
